//
//  PhotographerTableViewCell.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/14.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "PhotographerTableViewCell.h"
#import "LuBDefine.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"


@implementation PhotographerTableViewCell

- (void)dealloc{
    [_city_nameLabel release];
    [_introTextView release];
    [_petnameLabel release];
    [_photoImageView release];
    [_qqLabel release];
    [_weiboLabel release];
    [_lineLabel release];
    [_lineLabel2 release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createPhotographerTableViewCell];
    }
    return self;
}

- (void)createPhotographerTableViewCell{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    self.city_nameLabel = [[UILabel alloc] init];
//    self.city_nameLabel.backgroundColor = [UIColor redColor];
    [self addSubview:_city_nameLabel];
    [_city_nameLabel release];
    
    self.introTextView = [[UITextView alloc] init];
//    self.introTextView.backgroundColor = [UIColor purpleColor];
    [self addSubview:_introTextView];
    [_introTextView release];
    
    self.petnameLabel = [[UILabel alloc] init];
//    self.petnameLabel.backgroundColor = [UIColor yellowColor];
    [self addSubview:_petnameLabel];
    [_petnameLabel release];
    
    self.photoImageView = [[UIImageView alloc] init];
//    self.photoImageView.backgroundColor = [UIColor blueColor];
    [self addSubview:self.photoImageView];
    [_photoImageView release];
    
    self.qqLabel = [[UILabel alloc]init];
//    self.qqLabel.backgroundColor = [UIColor magentaColor];
    [self addSubview:_qqLabel];
    [_qqLabel release];
    
    self.weiboLabel = [[UILabel alloc]init];
//    self.weiboLabel.backgroundColor =[UIColor yellowColor];
    [self addSubview:_weiboLabel];
    [_weiboLabel release];
    
    self.lineLabel = [[UILabel alloc] init];
    self.lineLabel.backgroundColor = [UIColor grayColor];
    [self addSubview:_lineLabel];
    [_lineLabel release];
    
    self.lineLabel2 = [[UILabel alloc] init];
    self.lineLabel2.backgroundColor = [UIColor grayColor];
    [self addSubview:_lineLabel2];
    [_lineLabel2 release];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.photoImageView.frame = CGRectMake(5, 5, WIDTH / 8, WIDTH / 8);
    
    self.petnameLabel.frame = CGRectMake(WIDTH / 7 + 5, 5, WIDTH / 2, 20);
    self.petnameLabel.font = [UIFont systemFontOfSize:14];
    
    self.weiboLabel.frame = CGRectMake(WIDTH / 7 + 5, self.petnameLabel.frame.size.height + 10, WIDTH / 3 * 2, 20);
    self.weiboLabel.font = [UIFont systemFontOfSize:13];
    
    self.lineLabel.frame = CGRectMake(5, 5 + self.photoImageView.frame.size.height + 5, WIDTH - 10 , 0.5);
    self.lineLabel.font = [UIFont systemFontOfSize:12];

    self.city_nameLabel.frame  = CGRectMake(5, 17 + self.photoImageView.frame.size.height, WIDTH / 3, 20);
    self.city_nameLabel.font = [UIFont systemFontOfSize:13];
    
    self.qqLabel.frame = CGRectMake(5 + self.city_nameLabel.frame.size.width + 10, 17 + self.photoImageView.frame.size.height , WIDTH / 2, 20);
    self.qqLabel.font = [UIFont systemFontOfSize:13];

    self.lineLabel2.frame = CGRectMake(5, 25 + self.photoImageView.frame.size.height + self.qqLabel.frame.size.height, WIDTH - 10, 0.5);
    
    self.introTextView.frame = CGRectMake(5, 30 + self.photoImageView.frame.size.height + self.qqLabel.frame.size.height + 5, WIDTH - 10, 50);
    self.introTextView.editable = NO;
    self.introTextView.backgroundColor = [UIColor clearColor];
    self.introTextView.font = [UIFont systemFontOfSize:13];

}

- (void)setPhotograph:(Photograph *)photograph{
    if (_photograph != photograph) {
        [_photograph release];
        _photograph = [photograph retain];
    }
    NSURL *photoUrl = [NSURL URLWithString:photograph.photo];
    [self.photoImageView sd_setImageWithURL:photoUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    self.petnameLabel.text = photograph.petname;
    self.weiboLabel.text = [NSString stringWithFormat:@"微博 : %@", photograph.weibo];
    self.city_nameLabel.text =[NSString stringWithFormat:@"城市 : %@", photograph.city_name];
    self.qqLabel.text = [NSString stringWithFormat:@"QQ : %@", photograph.qq];
    self.introTextView.text = photograph.intro;
}

+ (PhotographerTableViewCell *)photographerTableViewCellWithTableView:(UITableView *)tableView{
    static NSString *photorapherCell = @"photorapherCell";
    PhotographerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:photorapherCell];
    if (!cell) {
        cell = [[[PhotographerTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:photorapherCell] autorelease];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

@end
